﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chowpoo.Common;
using Chowpoo.Util;
using CourseSystem.Common;
using CourseSystem.Common.Helpers;
using CourseSystem.Core.BLL;
using CourseSystem.Core.Enum;
using CourseSystem.Stat.ActionFilter;
using Webdiyer.WebControls.Mvc;

namespace CourseSystem.Web.Controllers
{
    [UserAuth(UserType = UserTypeEnum.Teacher)]
    public class AdminCommentController : BaseController
    {
        //
        // GET: /AdminComment/
        [UserAuth(UserType = UserTypeEnum.Admin)]
        public ActionResult Index()
        {
            return View();
        }
        [UrlStatFilter]
        public ActionResult CourseComment()
        {
            return View();
        }

        [UserAuth(UserType = UserTypeEnum.Admin)]
        public ActionResult TeacherStat()
        {
            return View();
        }
        [UrlStatFilter]
        public ActionResult CourseStat()
        {
            return View();
        }

        public ActionResult CommentListUc(int? pid, int type, int? teacherId, int reviewerType, int? rank)
        {
            rank = rank.CheckInt(0);
            CommonRequest.ClearCache();
            teacherId = teacherId.CheckInt(0);
            var list = CourseCommentBLL.GetList(type, teacherId.Value, reviewerType, rank.Value).OrderByDescending(o => o.Id);
            var model = list.ToPagedList(pid ?? 1, CommonHelper.PageSize);
            if (type == 0)
                return PartialView(model);
            return PartialView("CourseCommentListUc", model);
        }
        [UserAuth(UserType = UserTypeEnum.Admin)]
        public ActionResult TeacherStatListUc(int teacherId)
        {
            CommonRequest.ClearCache();
            ViewData["id"] = teacherId;
            return PartialView();
        }

        public ActionResult CourseStatListUc()
        {
            CommonRequest.ClearCache();
            return PartialView();
        }

        public ActionResult DetailsUc(int id)
        {
            var info = CourseCommentBLL.Get(id);
            if (info == null)
                return NotFound();
            return PartialView(info);
        }

        [UserAuth(UserType = UserTypeEnum.Admin)]
        public ActionResult CommentDel(int id, int type)
        {
            if (CourseCommentBLL.Del(id))
                SetAlertMsg("删除成功.", true);
            if (type == 0)
                return RedirectToAction("Index");
            return RedirectToAction("CourseComment");
        }

    }
}
